﻿using System.Net.Http;
using Kstopa.WebApi.Core.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;


namespace Kstopa.WebApi.Core.Middlewares
{
    public class ApiInfoMiddleware : IMiddleware, ITransientDependency
    {
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            context.Response.OnStarting(() =>
            {
                if (context.Response.StatusCode == StatusCodes.Status200OK
&& context.Response.Headers["Content-Type"].ToString() == "application/vnd.ms-excel")
                {
                    context.FileAttachmentHandle($"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.xlsx");
                }
                return Task.CompletedTask;
            });

            await next(context);



        }
    }
}
